﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;

namespace DataForest.View.Converter
{
    class IsTargetColumConverter : IMultiValueConverter
    {

        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            DataGridCell cell = null;
            DataColumn column = null;
            DataGridColumnHeader header = null;
            foreach (var item in values)
            {
                if (item is DataGridCell) { cell = item as DataGridCell; }
                if (item is DataColumn) { column = item as DataColumn; }
                if (item is DataGridColumnHeader) { header = item as DataGridColumnHeader; }
            }

            if (cell != null && column != null)
            {
                if (cell.Column != null) {

                    return cell.Column.SortMemberPath == column.ColumnName;
                }
            }
            if (header != null && column != null)
            {
                if (header.Column != null)
                {

                    return header.Column.SortMemberPath == column.ColumnName;
                }
            }
            return false;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
